<?php

class GmToolsService
{

    /**
     * @var GmToolsService
     */
    private static $instance;

    /**
     * 单例函数
     * @return GmToolsService
     */
    public static function get()
    {
        if (!self::$instance) {
            self::$instance = new GmToolsService();
        }
        return self::$instance;
    }

    /**
     * VisitInitService constructor.
     */
    private function __construct()
    {

    }

    public function getLanguageString($type)
    {
        switch ($type) {
            case 1:
                return GameConst::LANGUAGE_EN;
            case 2:
                return GameConst::LANGUAGE_CN;
        }
        return GameConst::LANGUAGE_EN;
    }

    public function getLanguageType($type)
    {
        switch ($type) {
            case GameConst::LANGUAGE_EN:
                return 1;
            case GameConst::LANGUAGE_CN:
                return 2;
        }
        return 1;
    }

    public function getUserInfo($params)
    {
        // [["game_user_id",["Jake","eq"]],["character_name",["1","eq"]]]
        $_res = array();
        $userId = FriendService::get()->getUserIdFromFriendCode($params[0][1][0]);
        if (!$userId) {
            return $_res;
        }
        $BaseMoney = array();
        $RoleName = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_TOWN_NAME);
        $Level = UserService::get()->getUserLevel($userId);
        $BaseMoney['CollectionToken'] = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_COLLECTION_TOKEN);
        $BaseMoney['AirplaneTicket'] = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_AIRPLANE_TICKET);
        $BaseMoney['Token'] = UserService::get()->getToken($userId);
        $BaseMoney['CocToken'] = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_COC_TOKEN);
        $BaseMoney['Money'] = PayService::get()->getMoney($userId);
        /** @var $coc CocVo */
        $coc = CocService::get()->getUserCoc($userId, false);
        $Guild = (!$coc) ? '' : $coc->getName();
        $UnlockedTime = GameService::get()->getLockTime($userId);
        $UnlockedTime = -1 == $UnlockedTime ? '' : date("Y-m-d H:i:s", $UnlockedTime);
        $sdkId = UserService::get()->getPlatformId($userId, 'sdk');

        $_res['RoleName'] = $RoleName;
        $_res['RoleId'] = $userId;
        $_res['AccountId'] = $params[0][1][0];
        $_res['Level'] = $Level;
        $_res['BaseMoney'] = $BaseMoney;
        $_res['LastTime'] = date("Y-m-d H:i:s", UserService::get()->getUserLastLoginTime($userId));
        $_res['LastIP'] = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_LAST_IP);
        $_res['Status'] = '';
        $_res['UnlockedTime'] = $UnlockedTime;
        $language = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_USER_LANG);
        $_res['Language'] = $this->getLanguageType($language);
        $_res['Dollars'] = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_PAY);
        $_res['Guild'] = $Guild;
        $_res['RegistrationTime'] = date("Y-m-d H:i:s", UserService::get()->getUserRegisterTime($userId));
        $_res['RegistrationIP'] = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_REGISTRATION_IP);
        $_res['SdkId'] = $sdkId;

        SzLogger::get()->debug("------GM Return 0001:---------" . var_export($_res, true) . "------------");

        return $_res;
        /*
            {'RoleName': '杰克逊', 'RoleId': '198347', 'AccountId': '1029489588', 'Level': 10,
            'BaseMoney':{'钻石':XXX,'金币':XXX}, 'LastTime': '2016-01-01 12:00:00','LastIP':'192.168.1.1','Status': "",
            'UnlockedTime':'2016-01-01 12:00:00',Language:'English', 'Dollars':'12','Guild':'天下会',
            RegistrationTime:'2016-01-01 12:00:00','RegistrationIP':'2016-01-01 12:00:00','SdkId':'34434234234asdfsadasd'}
        */
    }

    public function changeUserInfo($params, $params2)
    {
        /*
            "search": [
                ["game_user_id", ["Jake", "eq"]],
                ["character_name", ["1", "eq"]]
            ],
            "replace": [
                ["CollectionToken", "20"],
                ["AirplaneTicket", "30"]，
                ["Token", "30"]，
                ["CocToken", "30"]，
                ["Money", "30"]，
                ["UnlockedTime":'2016-04-1 12:00:00']
            ]
         */
        $_res = array();
        $userId = FriendService::get()->getUserIdFromFriendCode($params[0][1][0]);
        if (!$userId) {
            return $_res;
        }
        $BaseMoney = array();
        $CollectionToken = $params2[0][1];
        $AirplaneTicket = $params2[1][1];
        $Token = $params2[2][1];
        $CocToken = $params2[3][1];
        $Money = $params2[4][1];
        $UnlockedTime = $params2[5][1];
        $UnlockedTime = strtotime($UnlockedTime);
        if (!$UnlockedTime)
            $UnlockedTime = -1;
        GameService::get()->updateBlacklist($userId, $UnlockedTime);
        $CollectionToken_old = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_COLLECTION_TOKEN);
        UserService::get()->updateProfileInfo($userId, GameConst::USER_INFO_TYPE_COLLECTION_TOKEN, $CollectionToken_old + $CollectionToken);
        $AirplaneTicket_old = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_AIRPLANE_TICKET);
        UserService::get()->updateProfileInfo($userId, GameConst::USER_INFO_TYPE_AIRPLANE_TICKET, $AirplaneTicket_old + $AirplaneTicket);
        GameService::get()->handleEntity($userId, GameConst::ENTITY_ACTION_GET_TOKEN, $Token, true);
        $CocToken_old = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_COC_TOKEN);
        UserService::get()->updateProfileInfo($userId, GameConst::USER_INFO_TYPE_COC_TOKEN, $CocToken_old + $CocToken);
        GameService::get()->handleEntity($userId, GameConst::ENTITY_ACTION_GET_MONEY, $Money, true);


        $RoleName = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_TOWN_NAME);
        $Level = UserService::get()->getUserLevel($userId);
        $BaseMoney['CollectionToken'] = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_COLLECTION_TOKEN);
        $BaseMoney['AirplaneTicket'] = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_AIRPLANE_TICKET);
        $BaseMoney['Token'] = UserService::get()->getToken($userId);
        $BaseMoney['CocToken'] = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_COC_TOKEN);
        $BaseMoney['Money'] = PayService::get()->getMoney($userId);
        /** @var $coc CocVo */
        $coc = CocService::get()->getUserCoc($userId, false);
        $Guild = (!$coc) ? '' : $coc->getName();
        $UnlockedTime = GameService::get()->getLockTime($userId);
//        SzLogger::get()->debug('-------------------'.$UnlockedTime);
        $UnlockedTime = -1 == $UnlockedTime ? '' : date("Y-m-d H:i:s", $UnlockedTime);
//        SzLogger::get()->debug('-------------------'.$UnlockedTime);
        $_res['RoleName'] = $RoleName;
        $_res['RoleId'] = $userId;
        $_res['AccountId'] = $params[0][1][0];
        $_res['Level'] = $Level;
        $_res['BaseMoney'] = $BaseMoney;
        $_res['LastTime'] = date("Y-m-d H:i:s", UserService::get()->getUserLastLoginTime($userId));
        $_res['LastIP'] = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_LAST_IP);
        $_res['Status'] = '';
        $_res['UnlockedTime'] = $UnlockedTime;
        $language = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_USER_LANG);
        $_res['Language'] = $this->getLanguageType($language);
        $_res['Dollars'] = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_PAY);
        $_res['Guild'] = $Guild;
        $_res['RegistrationTime'] = date("Y-m-d H:i:s", UserService::get()->getUserRegisterTime($userId));
        $_res['RegistrationIP'] = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_REGISTRATION_IP);
        return $_res;
        /*
            {'RoleName': '杰克逊', 'RoleId': '198347', 'AccountId': '1029489588', 'Level': 10,
            'BaseMoney':{'钻石':XXX,'金币':XXX}, 'LastTime': '2016-01-01 12:00:00','LastIP':'192.168.1.1','Status': "",
            'UnlockedTime':'2016-01-01 12:00:00',Language:'English', 'Dollars':'12','Guild':'天下会',
            RegistrationTime:'2016-01-01 12:00:00','RegistrationIP':'2016-01-01 12:00:00'}
        */
    }

    public function getUserDetailedInfo($params)
    {
        /*
         {
             ["game_user_id", ["Jake", "eq"]],
             ["character_name", ["1", "eq"]]
          }
         */
        $_res = array();
        $userId = FriendService::get()->getUserIdFromFriendCode($params[0][1][0]);
        if (!$userId) {
            return $_res;
        }

        $Language = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_USER_LANG);
        /**
         * @var WarehouseVoList $warehouseList
         * @var WarehouseVo $itemWarehouse
         * @var WarehouseVo $flowerWarehouse
         */
        $warehouseList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_WAREHOUSE);
        $Warehouse = array();
        $ItemWarehouse = array();
        $itemWarehouse = $warehouseList->getElement(GameConst::ITEM_TYPE_WAREHOUSE_BUILDING, false);
        if (!$itemWarehouse) {
            throw new SzException(25013);
        }
        $ItemWarehouse['capacity'] = $itemWarehouse->getStock();
        $ItemWarehouse['items'] = array();
        /**
         * @var ModuleItemVoList $moduleItemVoList
         */
        $moduleItemVoList = SzPersister::get()->getVoList($userId, ModuleItemConst::ORM_NAME_ITEM);
        foreach ($moduleItemVoList->toArray() as $moduleItemVoArr) {
            foreach ($moduleItemVoArr as $moduleItemVo) {
                $item = $moduleItemVoList->getElement($moduleItemVo['itemId'], false);
                if (!$item) continue;
                $_itemConfig = SzConfig::get()->loadAppConfig(ModuleItemConst::CONFIG_ITEM_DEFS, $item->getItemDefId(), true, false);
                if (!$_itemConfig) continue;
                if ($_itemConfig['warehouseId'] != GameConst::ITEM_TYPE_WAREHOUSE_BUILDING) continue;
                $_content = SzConfig::get()->loadAppConfig(GameConst::CONFIG_EN, $_itemConfig['name'], true);
                if (!$_content) continue;
                $itemObj = array();
                $itemObj['id'] = $item->getItemDefId();
                $itemObj['name'] = $_content['value'];
                $itemObj['num'] = $item->getFreeCount();
                $ItemWarehouse['items'][] = $itemObj;
            }
        }
        $Warehouse[] = $ItemWarehouse;
        $_flowerWarehouse = array();
        $flowerWarehouse = $warehouseList->getElement(GameConst::ITEM_TYPE_WAREHOUSE_FLOWER, false);
        if (!$flowerWarehouse) {
            throw new SzException(25014);
        }
        $_flowerWarehouse['capacity'] = $flowerWarehouse->getStock();
        $_flowerWarehouse['items'] = array();
        /**
         * @var ModuleItemVoList $moduleItemVoList
         */
        $moduleItemVoList = SzPersister::get()->getVoList($userId, ModuleItemConst::ORM_NAME_ITEM);
        foreach ($moduleItemVoList->toArray() as $moduleItemVoArr) {
            foreach ($moduleItemVoArr as $moduleItemVo) {
                $item = $moduleItemVoList->getElement($moduleItemVo['itemId'], false);
                if (!$item) continue;
                $_itemConfig = SzConfig::get()->loadAppConfig(ModuleItemConst::CONFIG_ITEM_DEFS, $item->getItemDefId(), true, false);
                if (!$_itemConfig) continue;
                if ($_itemConfig['warehouseId'] != GameConst::ITEM_TYPE_WAREHOUSE_FLOWER) continue;
                $_content = SzConfig::get()->loadAppConfig(GameConst::CONFIG_EN, $_itemConfig['name'], true);
                if (!$_content) continue;
                $itemObj = array();
                $itemObj['id'] = $item->getItemDefId();
                $itemObj['name'] = $_content['value'];
                $itemObj['num'] = $item->getFreeCount();
                $_flowerWarehouse['items'][] = $itemObj;
            }
        }
        $Warehouse[] = $_flowerWarehouse;

        $coc = CocService::get()->getUserCoc($userId, false);
        $Guild = array();
        if ($coc) {
            $_cocMemberConfig = SzConfig::get()->loadAppConfig(GameConst::CONFIG_COC_MEMBER, $coc->getLevel(), true);

            $position = '成员';
            if ($coc->getChairmanUserId() == $userId) {
                $position = '会长';
            }
            if (in_array($userId, $coc->getRawViceChairmanUserIdList())) {
                $position = '副会长';
            }

            $Guild = array(
                'name' => $coc->getName(),
                'level' => $coc->getLevel(),
                'people_num' => $coc->getMemberCount(),
                'people_limit' => $_cocMemberConfig['memberLimit'],
                'task_progress' => '',
                'position' => $position
            );
        }

        $friends = array();
        $friends['num'] = 0;
        $friends['name'] = json_encode(array());
        /**
         * @var FriendsVo $myFriendsInfo
         */
        $myFriendsInfo = SzPersister::get()->getVo($userId, GameConst::ORM_NAME_FRIENDS);
        foreach ($myFriendsInfo->getRawFriendsList() as $friendsId) {
            $friendsObj = array();
            $friendsObj['name'] = UserService::get()->getTownName($friendsId);
            $friends['name'][] = $friendsObj;
        }

        /**
         * @var BuildingVoList $buildingList
         */
        $RoomItems = array();
        $buildingList = SzPersister::get()->getVoList($userId, GameConst::ORM_NAME_BUILDING);
        foreach ($buildingList->toArray() as $buildingVo) {
            $buildingDefId = $buildingVo['buildingDefId'];
            $_itemConfig = SzConfig::get()->loadAppConfig(ModuleItemConst::CONFIG_ITEM_DEFS, $buildingDefId, true, false);
            if (!$_itemConfig) continue;
            $_content = SzConfig::get()->loadAppConfig(GameConst::CONFIG_EN, $_itemConfig['name'], true);
            if (!$_content) continue;
            $RoomItems[$buildingDefId] = $_content['value'];
        }

        $configTask = SzConfig::get()->loadAppConfig(GameConst::CONFIG_TASK, null, true);
        $achievementFinished = UserService::get()->getInfo($userId, GameConst::USER_INFO_TYPE_ACHIEVEMENT_FINISHED);
        $Achievement = array();
        foreach ($configTask as $key => $value) {
            if ($value['taskType'] != 98) continue;
            $_content = SzConfig::get()->loadAppConfig(GameConst::CONFIG_EN, $value['title'], true);
            if (!$_content) continue;
            $v = array();
            if (in_array($key, $achievementFinished)) $v[$_content['value']] = 1;
            else $v[$_content['value']] = 2;
            $Achievement[] = $v;
        }

        $_res['target_id'] = $params[0][1][0];
        $_res['AreaList'] = json_encode(array("all"));
        $_res['Language'] = $this->getLanguageType($Language);
        $_res['Warehouse'] = json_encode($Warehouse);
        $_res['Achievement'] = json_encode($Achievement);
        $_res['UnlockedItems'] = array();
        $_res['Guild'] = ($Guild);
        $_res['friends'] = ($friends);
        $_res['FB'] = '[]';
        $extra = array();
        $extra['RoomItems'] = $RoomItems;
        $extra['Machine'] = array();
        $extra['Land'] = array();
        $extra['OutRoom'] = array();
        $_res['extra'] = $extra;
        return $_res;
        /*
            "target_id": 1235467，
            "AreaList": ["all"]，
            "Language": 0,
            "Warehouse"(个人仓库):
            [
                {
                    'capacity'（容量）:20,
                    items:
                        [
                            {
                                "id":"道具id"，
                                'name':"道具名字",
                                'num':'个数'
                            },
                            {
                                "id":"道具id"，
                                'name':"道具名字",
                                'num':'个数'
                            }
                        ]
                },
                {'capacity':20,items:[{"id":"道具id"，'name':"道具名字",'num':'个数'},{"id":"道具id"，'name':"道具名字",'num':'个数'}]}
            ],
             "Achievement":[{"成就名称1":1},{"成就名称2":0}](1是已经完成，2是没有完成),
              'UnlockedItems'（功能性解锁的建筑）:{"XXXX":0,"XXXX":1}(0未解锁，1解锁)
              'Guild'（公会）:
               {
                    'name':"天下会",
                    'level':12,limit（入会限制）:'',
                    'people_num（目前人数）':20,
                    'people_limit（总人数）':10,
                    'task progress（公会任务进度）':25%,
                    'position'(玩家职务):'会长'
                },
              'friends'（好友）:{'num'（好友数目）:20,name（好友名字）::[{'name':'jack'},{'name':'Tim'}]}，
              'FB':[{'副本名称':'XXX','status':0},{'副本名称':'XXX','status':1}] （0副本未完成，1副本已完成）
              'extra':[
             "RoomItems"（玩家室内物品）:{"XXXX":"XXXX","XXXX":"XXXXX"}(玩家室内物品统一这个格式)
             "Machine"（玩家机器）:{"XXXX":"XXXX","XXXX":"XXXXX"},
              'Land'（玩家土地）:{"XXXX":"XXXX","XXXX":"XXXXX"},
              'OutRoom'（玩家室外物品）:{"XXXX":"XXXX","XXXX":"XXXXX"}]
        */
    }

    public function setNotice($params)
    {
        SzLogger::get()->debug('------------- GM -- 4 ----------- setNotice ------ begin');
        /*
         {
            "StartTime": "2017-01-01 12:00:00",
            "EndTime": "2017-02-01 12:00:00",
            "Title": "公告",
            'Sort': 4,(排序数字 数字越大 排在越前面),
            'Channel': 1,(1是h5,2是app store,3是google play),
            'Picture': '',
            "AreaList": ["all"]，
            "Language": 0,
            "Content": "文本[ff0000]带[-][00ff00][颜色][-]",
            }
        */
        $_res = array();
        $StartTime = $params['StartTime'];
        $EndTime = $params['EndTime'];
        $Title = $params['Title'];
        $Sort = $params['Sort'];
        $Channel = $params['Channel'];
        $Picture = $params['Picture'];
        $AreaList = $params['AreaList'];
        $Language = $params['Language'];
        $Content = $params['Content'];


        $StartTime = strtotime($StartTime);
        if (!$StartTime)
            throw new SzException(25004);
        $EndTime = strtotime($EndTime);
        if (!$EndTime)
            throw new SzException(25004);

        list($_isSuccess, $_noticeId) = GmToolsNoticeService::get()->create($Language, $StartTime, $EndTime, $Title, $Content, $Sort, $Channel, $Picture);
        if (!$_isSuccess)
            throw new SzException(25009);

        $_res['target_id'] = $_noticeId;
        $_res['AreaList'] = json_encode($AreaList);
        $_res['Language'] = $Language;
        return $_res;
        /*
        {
            "target_id": 1235467，
            "AreaList": ["all"]，
            "Language": 0,
        }
        */
    }

    public function changeNotice($params)
    {
        /*
        {
            "id": 321321,
            "StartTime": "2017-01-01 12:00:00",
            "EndTime": "2017-02-01 12:00:00",
            "Title": "公告",
            'Sort': 4,(排序数字 数字越大 排在越前面),
            'Channel': 1,(1是h5,2是app store,3是google play),
            'Picture': '',
            "Content": "文本[ff0000]带[-][00ff00][颜色][-]",
            "AreaList": ["all"],
            "Language": 0,
        }
        */
        $_res = array();
        $id = $params['id'];
        $StartTime = $params['StartTime'];
        $EndTime = $params['EndTime'];
        $Title = $params['Title'];
        $Sort = $params['Sort'];
        $Channel = $params['Channel'];
        $Picture = $params['Picture'];
        $Content = $params['Content'];
        $AreaList = $params['AreaList'];
        $Language = $params['Language'];

        $StartTime = strtotime($StartTime);
        if (!$StartTime)
            throw new SzException(25004);
        $EndTime = strtotime($EndTime);
        if (!$EndTime)
            throw new SzException(25004);

        $_isSuccess = GmToolsNoticeService::get()->changeNotice($id, $Language, $StartTime, $EndTime, $Title, $Content, $Sort, $Channel, $Picture);
        if (!$_isSuccess)
            throw new SzException(25011);

        $_res['target_id'] = $id;
        $_res['AreaList'] = json_encode($AreaList);
        $_res['Language'] = $Language;
        return $_res;
        /*
        {
            "target_id": 1235467，
            "AreaList": ["all"]，
            "Language": 0,
        }
        */
    }

    public function deleteNotice($params)
    {
        /*
            "id": 321321,
            "AreaList": ["all"],
            "Language": 0,
        */
        $_res = array();
        $id = $params['id'];
        $AreaList = $params['AreaList'];
        $Language = $params['Language'];

        $_isSuccess = GmToolsNoticeService::get()->deleteNotice($id);
        if (!$_isSuccess)
            throw new SzException(25012);

        $_res['target_id'] = $id;
        $_res['AreaList'] = json_encode($AreaList);
        $_res['Language'] = $Language;
        return $_res;
        /*
        {
            "target_id": 1235467，
            "AreaList": ["all"]，
            "Language": 0,
        }
        */
    }

    public function getNotice($params)
    {
        /*
            "id": 321321,
            "AreaList": ["all"],
            "Language": 0,
        */
        $_res = array();
        $id = $params['id'];
        $AreaList = $params['AreaList'];

        /** @var $_gmSaveNoticeVo GmSaveNoticeVo */
        list($_isSuccess, $_gmSaveNoticeVo) = GmToolsNoticeService::get()->getNotice($id);
        if (!$_isSuccess)
            throw new SzException(25010);

        $_res['target_id'] = $_gmSaveNoticeVo->getNoticeId();
        $_res['StartTime'] = date("Y-m-d H:i:s", $_gmSaveNoticeVo->getStartTime());
        $_res['EndTime'] = date("Y-m-d H:i:s", $_gmSaveNoticeVo->getEndTime());
        $_res['Title'] = $_gmSaveNoticeVo->getTitle();
        $_res['Content'] = $_gmSaveNoticeVo->getContent();
        $_res['AreaList'] = json_encode($AreaList);
        $_res['Language'] = $_gmSaveNoticeVo->getLanguage();
        return $_res;
        /*
        {
            "target_id": 321321,
            "StartTime": "2017-01-01 12:00:00",
            "EndTime": "2017-02-01 12:00:00",
            "Title": "公告",
            "Content": "文本[ff0000]带[-][00ff00][颜色][-]",
            "AreaList": ["all"],
            "Language": 0,
        }
        */
    }

    public function selectUserInfoByOrder($params)
    {
        /*
        {
            "code": 8,
            "data":
                {
                    "action": "select",
                    "params":
                        {
                            "orderIds": ["ZFSQA120170920c2e1a96e9db28832","ZFSQA120170920c2e1a96e9db28832"]
                        }
                },
            "op": "query"
        }
        */
        $_res = [];
        $_res["code"] = 0;
        $_res["message"] = 'success';
        $_res["orderInfo"] = [];
        $orderIds = $params["orderIds"];
        $orderCount = count($orderIds);
        $selectIds = "(";
        for ($i = 0; $i < $orderCount; $i++) {
            $orderToken = $orderIds[$i];
            $selectIds .= "\"" . $orderToken . ($i + 1 < $orderCount ? "\"," : "\")");
        }
        $serversConfig = SzConfig::get()->loadAppConfig('database', 'Payment');
        $instance = new SzMySqlDb($serversConfig);
        //select userId from flowertown_payment_dev.module_payment_order where platformToken in ("ZFSQA1201709201c9c44789deaa4c3,ZFSQA12017092032ff30ea9de59658");
        $sql = "select userId,platformToken  from " . $serversConfig['DB_NAME'] . ".module_payment_order where platformToken in $selectIds";
        $temp = $instance->select($sql);
        $userIds = [];
        foreach ($temp as $infoArray) {
            $orderInfo = [];
            $orderInfo["userId"] = FriendService::get()->getFriendsCode($infoArray["userId"])->getFriendCode();
            $orderInfo["level"] = UserService::get()->getUserLevel($infoArray["userId"]);
//            $orderInfo["userCode"] = (FriendService::get()->getFriendsCode($infoArray["userId"]))->getFriendCode();
            $_res["orderInfo"][$infoArray["platformToken"]] = $orderInfo;
        }
        return $_res;
        /*
        {
            code：0,
            message: 'success',
            orderInfo:
            {
                "ZFSQA120170920c2e1a96e9db28832":
                    {
                        userId:AGHIKBKJ,
                        level:20,
                    }
            }
        }
        */
    }

    /*
        {
            "code": 12,
            "data":
                {
                    "action": "select",
                    "params":
                        {
                            "appId":12365
                            "areaId":12365
                        }
                },
            "op": "query"
        }
        */
    public function getUserLive($params)
    {
        $_res = [];
        $_res['appId'] = -1;
        $_res['areaId'] = 9999;
        $_res['timeFrequency'] = SzTime::MINUTE;
        $_res['date'] = date('Y-m-d H:m:',GameService::get()->getReqTime());
        $_res['count'] = count(SzCacheFactory::get()->getAppCache()->keys(GameConst::CACHE_KEY_USER_LIVE . ':*'));
        return $_res;
    }
}